package com.iweipan.base;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;

import com.iweipan.MyApplication;
import com.iweipan.R;
import com.jaeger.library.StatusBarUtil;
import com.zhy.autolayout.AutoLayoutActivity;

import java.lang.ref.WeakReference;

import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/11/9.
 */

public abstract class WPBaseActivity extends AutoLayoutActivity implements WPInitActivity {

    /**
     * 日志输出标志
     **/
    protected final String TAG = this.getClass().getSimpleName();
    /**
     * 当前Activity渲染的视图View
     **/
    private View mContextView = null;

    /**
     * 当前Activity的弱引用，防止内存泄露
     **/
    private static WeakReference<Activity> context = null;

    private MyApplication uhApplication;

    public int color;
    public int statusBarAlpha;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContextView = LayoutInflater.from(this).inflate(bindLayout(), null);
        setContentView(mContextView);
        color = getResources().getColor(R.color.actionbar_title_bg);
        statusBarAlpha = 60;
        initToolbarColor();

        StatusBarUtil.setColor(this, color, statusBarAlpha);

        ButterKnife.bind(this);
        uhApplication = new MyApplication();
        context = new WeakReference<Activity>(this);
        uhApplication.pushTask(context);
        /**初始化试图*/
        initView(mContextView);

        /**业务操作*/
        doBusiness(this);

    }

    @Override
    protected void onResume() {
        super.onResume();
        resume();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        destroy();
        uhApplication.removeTask(context);
    }

    /**
     * 获取当前Activity
     *
     * @return
     */
    @Nullable
    public static Activity getContext() {
        if (null != context)
            return context.get();
        else
            return null;
    }
}
